package com.ali.resource.CompoentPage;

import com.ali.resource.ShareTools.TeaopenapiClient;
import com.aliyun.rds20140815.Client;
import com.aliyun.rds20140815.models.*;
import com.aliyun.teaopenapi.models.Config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class RdsComponent {

    @Autowired
    private TeaopenapiClient teaopenapiClient;

    public Client getRdsClient() throws Exception {

        Config rdsClient = teaopenapiClient.getClient();
        // 必填 您的地域信息
        rdsClient.setEndpoint("rds.aliyuncs.com");
        return new Client(rdsClient);
    }

    public com.aliyun.rds20140815.models.DescribeDBInstancesRequest getRdsReQuest(){
        com.aliyun.rds20140815.models.DescribeDBInstancesRequest describeDBInstancesRequest = new com.aliyun.rds20140815.models.DescribeDBInstancesRequest();
        describeDBInstancesRequest.setRegionId("cn-shanghai");
        return describeDBInstancesRequest;
    }

    public com.aliyun.rds20140815.models.DescribeDBInstancesResponse getInstanceResource(com.aliyun.rds20140815.models.DescribeDBInstancesRequest getRdsReQuest) throws Exception {
        Client client = this.getRdsClient();
        DescribeDBInstancesResponse describeDBInstancesResponse = client.describeDBInstancesWithOptions(getRdsReQuest, teaopenapiClient.getRunTime());
        return describeDBInstancesResponse;
    }

    public com.aliyun.rds20140815.models.DescribeDBInstanceAttributeResponse getInstanceInfo(String InstanceId) throws Exception {
        DescribeDBInstanceAttributeRequest describeDBInstanceAttributeRequest = new DescribeDBInstanceAttributeRequest();
        describeDBInstanceAttributeRequest.setDBInstanceId(InstanceId);

        Client client = this.getRdsClient();
        DescribeDBInstanceAttributeResponse describeDBInstanceAttributeResponse = client.describeDBInstanceAttributeWithOptions(describeDBInstanceAttributeRequest, teaopenapiClient.getRunTime());
        return describeDBInstanceAttributeResponse;
    }

    public com.aliyun.rds20140815.models.DescribeDBInstanceByTagsResponse getInstanceByTagsInfo(String InstanceId) throws Exception {
        DescribeDBInstanceByTagsRequest describeDBInstanceByTagsRequest = new DescribeDBInstanceByTagsRequest();
        describeDBInstanceByTagsRequest.setRegionId("cn-shanghai");
        describeDBInstanceByTagsRequest.setDBInstanceId(InstanceId);

        Client client = this.getRdsClient();
        DescribeDBInstanceByTagsResponse describeDBInstanceByTagsResponse = client.describeDBInstanceByTagsWithOptions(describeDBInstanceByTagsRequest, teaopenapiClient.getRunTime());
        return describeDBInstanceByTagsResponse;
    }


}
